/**
* 订单管理 交易订单
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="keyword" placeholder="输入用户手机号/昵称"></el-input>
        <!-- <el-input size="small" v-model="formInline.machineNo" placeholder="输入邀请人用户手机号"></el-input> -->
      </el-form-item>

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-form :inline="true" class="user-search">
      <el-form-item label="平台押金：">
        <el-input size="small" v-model="rate" placeholder=""></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" @click="setServiceCharge">确认设置</el-button>
      </el-form-item>
    </el-form>
    
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
      element-loading-text="拼命加载中" style="width: 100%;">
    
      <el-table-column sortable prop="id" label="id" width="50" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="name" label="头像" width="120">

        <template slot-scope="scope">
          <img style="width: 90px;height: 90px;" :src="scope.row.headPortrait">
        </template>

      </el-table-column>
      <el-table-column sortable prop="username" label="用户昵称" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="mobile" label="手机号" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="balance" label="余额" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.balance / 100 }}</div>
        </template>
      </el-table-column>

      <el-table-column sortable prop="bailBalance" label="保证金" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.bailBalance / 100 }}</div>
        </template>
      </el-table-column>

      <el-table-column sortable prop="realName" label="真实姓名" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="identityCard" label="身份证" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="alipayAccount" label="支付宝" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="bankCard" label="银行卡" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="bankName" label="开户行" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="inviteId" label="邀请人" width="120" show-overflow-tooltip>
      </el-table-column>

      <el-table-column sortable prop="createTime" label="创建时间" width="150">
        <template slot-scope="scope">
          <div>{{ transformDate(scope.row.createTime) }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="success" @click="handleEdit(scope.row)">发送通知</el-button> -->
          <el-button size="mini" type="danger" @click="refundBailBalance(scope.$index, scope.row)">退押金</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

  </div>
</template>

<script>
import { getBailBalanceList, setServiceCharge, refundBailBalance } from '../../api/userMG'
import Pagination from '../../components/Pagination'




export default {
  data() {
    return {


      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',
      rate: "",

      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 20,
        total: 10
      },

      keyword: "",



    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(1)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {

    // 设置平台押金
    setServiceCharge() {
      this.loading = true;
      var parameter = {
        rate: this.rate * 100,
        id: 2
      };
      setServiceCharge(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: res.msg,
          });
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },
    refundBailBalance(index, row) {
      this.$confirm('确定要退款押金吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          refundBailBalance({ id: row.id })
            .then(res => {
              if (res.code == 200) {

                this.getdata(1)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
            })
        })
        .catch(() => {

        })
    },

    // 获取数据方法
    getdata(page) {
      this.loading = true;
      var parameter = {
        keyword: this.keyword,
        page: (page - 1) * 20,
      };
      getBailBalanceList(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.listData = res.data.list;
          this.rate = res.data.bail / 100;
          this.pageparm.currentPage = page;
          this.pageparm.total = res.data.count;
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },


    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(parm.currentPage)
    },
    // 搜索事件
    search() {
      this.getdata(1)
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.editForm = row
      this.from.userId = row.id;
    },

    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;

}
</style>